let _playTime = 0
let _tickerID = -1

// s 转为 00:00:00 格式字符串
function secondsToString(seconds) {
    // 获取时分秒
    var hours = Math.floor(seconds / 3600);
    var minutes = Math.floor((seconds % 3600) / 60);
    var secs = seconds % 60;

    // 格式化为00:00:00
    hours = hours < 10 ? '0' + hours : hours;
    minutes = minutes < 10 ? '0' + minutes : minutes;
    secs = secs < 10 ? '0' + secs : secs;

    return hours + ':' + minutes + ':' + secs;
}

function startRecording() {
    _tickerID = setInterval(() => {
        _playTime += 1
    }, 10)
}

function stopRecording() {
    clearInterval(_tickerID)
    _tickerID = -1
}

function resetRecording() {
    _playTime = 0
}

function getPlayTime() {
    return secondsToString(Math.floor(_playTime / 100))
}

export {
    startRecording,
    stopRecording,
    resetRecording,
    getPlayTime
}